How to compose a Matcher[Iterable[A]] from a Matcher[A] with specs testing framework

Posted by Garrett Rowe on Stack Overflow See other posts from Stack Overflow or by Garrett Rowe
Published on 2010-06-05T06:16:20Z Indexed on 2010/06/05 6:22 UTC
Read the original article Hit count: 281

Filed under:
|
|
|

If I have a Matcher[A] how do create a Matcher[Iterable[A]] that is satisfied only if each element of the Iterable satisfies the original Matcher.

class ExampleSpec extends Specification {
  def allSatisfy[A](m: => Matcher[A]): Matcher[Iterable[A]] = error("TODO")
  def notAllSatisfy[A](m: => Matcher[A]): Matcher[Iterable[A]] = allSatisfy(m).not    

   "allSatisfy" should {
     "Pass if all elements satisfy the expectation" in {
      List(1, 2, 3, 4) must allSatisfy(beLessThan(5))
    }

    "Fail if any elements do not satisfy the expectation" in {
      List(1, 2, 3, 5) must notAllSatisfy(beLessThan(5))
    }
  }
}

© Stack Overflow or respective owner

Related posts about scala

Related posts about composition